package day9;

public class code2 {

    public boolean isValidBST(TreeNode root) {

        return fun1(root,Integer.MIN_VALUE,Integer.MAX_VALUE);

    }

    public boolean fun1(TreeNode node,int bi,int sm){
        if(node==null) return  true;
        if(node.val<bi||node.val>sm) return false;
        if(node.left!=null){
            if(node.left.val>=node.val) return false;

        }
        if(node.right!=null){
            if(node.right.val<=node.val) return false;
        }

        return fun1(node.left,bi,node.val-1)&&fun1(node.right,node.val+1,sm);
    }



}
